<template>
  <a-card :bordered="false" class="card-area ccslh">
    <div class="table-page-search-wrapper" v-if="!visible">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <!-- <a-col :md="6" :sm="12">
            <a-form-item label="开始时间">
              <a-date-picker v-model="queryParam.start_time" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item label="结束时间">
              <a-date-picker v-model="queryParam.ent_time" />
            </a-form-item>
          </a-col> -->
          <a-col :md="6" :sm="12">
              <a-form-item label="院系">
                <a-select :disabled="selectMenu.yx.length === 1" :allowClear="true" showSearch :filterOption="filterOption" v-model="queryParam.yxm">
                  <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwh }} {{ i.dwmc }}</a-select-option>
                </a-select>
              </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
              <a-form-item label="年级">
                <a-select :allowClear="true" showSearch :filterOption="filterOption" v-model="queryParam.sznj">
                  <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
              <a-form-item label="学生类别">
                <a-select allowClear v-model="queryParam.xslbm">
                  <a-select-option v-for="i in TYPE0075" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
              <a-form-item label="贷款学年">
                <a-select allowClear v-model="queryParam.dknd">
                  <a-select-option v-for="i in TYPE0125" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
          </a-col>
          <a-col :md="8" :sm="16">
            <span class="table-page-search-submitButtons" >
              <a-button type="primary" @click="loadData()">查询</a-button>
              <a-button type="primary" @click="exportExcel">导出</a-button>
              <a-button style="margin-left: 8px" @click="() => queryParam = {yxm: selectMenu.yx.length === 1 ? queryParam.yxm : ''}">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- <a-table
      v-if="!visible"
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :data="loadData"
      :alert="options.alert"

      :pagination="false"
      :scroll="{x: 1600}"
    >
    </a-table> -->


    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :pagination="false"
       @change="handleTableChange"
    >

    </a-table>
  </a-card>
</template>

<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'
import moment from 'moment'

export default {
  name: 'TableList',
  components: {
    STable
  },
  data () {
    return {
      modelShow:false,
      // 高级搜索 展开/关闭
      advanced: true,
      // 查询参数
      queryParam: {},
      studentInfo:{},//学生信息
      postParams: {},
      stuInfo: {},
      // 表头
      pagination:{
        current:1
      },
      columns: [
        // {
        //   title: '序号',
        //   scopedSlots: { customRender: 'serial' }
        // },
        {
          title: '院系',
          dataIndex: 'yxm',
          width:200
        },
        {
          title: '总人数',
          dataIndex: 'totalCount'
        },
        {
          title: '贷款人数',
          dataIndex: 'dkrs'
        },
        {
          title: '未贷款人数',
          dataIndex: 'wdkrs',
        },
        {
          title: '贷款率（%）',
          dataIndex: 'dkl',
        },
        // {
        //   title: '操作',
        //   fixed: 'right',
        //   scopedSlots: { customRender: 'operation' },
        //   width: '150px'
        // }
      ],
      parameter: {
        pageNo: 1,
        pageSize: 10
      },
      selectMenu: {
        yx: [], // 院系
        zy: [] // 所属专业
      },
      selectedRowKeys: [],
      selectedRows: [],
      loading:false,
      data:[],

      // custom table alert & rowSelection
      options: {
        alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
        rowSelection: {
          selectedRowKeys: this.selectedRowKeys,
          onChange: this.onSelectChange
        }
      },
      optionAlertShow: true, // 是否显示alert，已选中
      visible: false,
      confirmLoading: false,
      editId: null,
    }
  },
  computed: {
    ...mapState({
      TYPE0125: state => state.app['TYPE0125'],
      TYPE0075: state => state.app['TYPE0075'],
      TYPE0126: state => state.app['TYPE0126'],
    })
  },
  created () {
    // this.$store.dispatch('app/sysInfo').then(data => {
    //   this.$set(this.queryParam, 'xn', data.schoolYear)
    // })
    this.$store.dispatch('app/setDictionary', 'TYPE0125')
    this.$store.dispatch('app/setDictionary', 'TYPE0075')
    this.$store.dispatch('app/setDictionary', 'TYPE0126')
    this.initSelectMenu()
    this.loadData()
  },
  beforeCreate () {
    this.form = this.$form.createForm(this)
  },
  methods: {
    refresh() {
      this.$refs.table.refresh(false)
    },
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
        if(this.selectMenu.yx && this.selectMenu.yx.length == 1){
          this.$set(this.queryParam, 'yxm', this.selectMenu.yx[0].dwh)
        }
        this.initDone = true
      })
    },
    loadData (parameter = {}) {
         if(!parameter.pageNum){
          this.pagination.current = 1
          parameter.pageNum = 1
        }
        let params = Object.assign(this.queryParam, parameter)
        this.loading = true;
          this.$api.student.studentloanSummaryList(params).then(res=>{
              const pagination = { ...this.pagination
             };
             pagination.total = 0
             if (res.data && res.data.total) {
               pagination.total = res.data.total;
             }
             this.data = []
             this.pagination = pagination;
             console.log(res.data.rows)
             console.log(res.data.rows.length)
             if (res.data.rows && res.data.rows.length) {
               this.data = res.data.rows;
             }
             console.log(this.data)
             this.loading = false;
          })
      },
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    // direct (data) {
    //   this.$router.push(`/student/stuStatus/search/stuView?xh=${data.xh}`)
    // },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    cancelRequest (row) {
      this.$api.student.studentLeaveCancel(row.id).then(res => {
        this.$message.success(res.msg)
        this.$refs.table.refresh(true)
      })
    },
    // 分页
      handleTableChange (pagination, filters, sorter) {
       console.log(pagination);
       const pager = { ...this.pagination };
       pager.current = pagination.current;
       this.pagination = pager;
       this.loadData({
         pageSize: 10,
         pageNum: pagination.current
       });
    },
    exportExcel () {
      let params = this.queryParam
      this.$export('/admissions/dksq/summary/export', {
        ...params
      })
    }
  }
}
</script>
<style lang="less">
.ccslh{
      table {
        table-layout:fixed;
      }
      tr td:nth-child(4){
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      tr td:nth-child(5){
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
}

</style>
